<?php
//模型
class CourseModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'course';
	}
	
	
	function get_list($arr,$page=1,$size=10){
		$where = 'status = 1';
		if(isset($arr['cid']) && !empty($arr['cid'])){
			$where .= " AND cid= '{$arr['cid']}'";
		}
		
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where {$where} limit ".($page-1)*$size.",{$size}";

		$query = $this->db->query($sql);
		$res = $query->result_array();
		
		
		$sql  = "select count(id) as num from ".$this->db->dbprefix.$this->table." where {$where} ";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		$count = $row['num'];
		
		return array('list'=>$res,'count'=>$count);
	}
	function get_lists($arr){
		$where = 'status = 1';
		if(isset($arr['cid']) && !empty($arr['cid'])){
			$where .= " AND cid= '{$arr['cid']}'";
		}		
		$sql  = "select * from ".$this->db->dbprefix.$this->table."  where {$where}  ";
		$query = $this->db->query($sql);
		$res = $query->result_array();
		return $res;
	}
	
	function get_info($user_id,$id){
		$info = $this->_id_get_info($id);
		if(!$info){
			return false;
		}
		
		if($info['cid']!==$user_id){
			return false;
		}
		return $info;
	}
	
	function ids_get_data($ids_arr){
		
		$ids  = implode(',',$ids_arr);
		if(empty($ids)){
			return false;
		}
		
		$where = " id in({$ids}) ";
		
		$sql = "select * from ".$this->db->dbprefix.$this->table." where {$where}";
		$query = $this->db->query($sql);
		$res  = $query->result_array();
		
		return $res;
	}

}

